package com.ambimmort.shj.service.generalfile;

import cn.net.greenet.common.db_service.BaseDao;
import cn.net.greenet.db.HibernateUtil;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.PrintWriter;
import java.sql.ResultSet;

/**
 * Created by 师梁 on 2015/7/30.
 */
@Service("del_IPBankService")
public class Del_IPBankService {
//    @Autowired
//    private SessionFactory hibernateSessionFactory;
    ResultSet rs = null;
    BaseDao baseDao = null;
    String sql = null;

    private void init() {
        baseDao = new BaseDao();
    }

    private void close() {
        if (baseDao != null) {
            baseDao.close();
        }
    }

    public boolean del(String dis){
        String[] arr = dis.split(",");
        boolean result = false;
        init();
        try {
            for (int i = 0; i < arr.length; i++) {
                sql="delete from Iprangeinfo s where s.id=?" ;
                Object[] param = {Integer.parseInt(arr[i])};
                rs=baseDao.executeSQL(sql,param);
            }
            result = true;
        } finally {
            close();
//            sf.close();
            return result;
        }
    }
//        String[] arr = dis.split(",");

//        boolean result = false;
//        Session session = hibernateSessionFactory.openSession();
//        session.clear();
//        try {
//            Transaction tx = session.beginTransaction();
//            for (int i = 0; i < arr.length; i++) {
//                Query query = session.createQuery("delete Iprangeinfo s where s.id=?");
//                query.setInteger(0, Integer.parseInt(arr[i]));
//                query.executeUpdate();
//            }
//            result = true;
//            tx.commit();
//        } finally {
//            session.close();
////            sf.close();
//            return result;
//        }
//    }

}
